package com.goldsprite.microhorigame.ecs;
import com.goldsprite.gameframeworks.ecs.component.*;
import com.goldsprite.gameframeworks.log.Debug;
import com.goldsprite.gameframeworks.ecs.component.FullCollisionResult;

public class FootTriggerComponent extends CircleColliderComponent {
	private boolean isGround;
	private ColliderComponent bodyColl;

	public FootTriggerComponent() {
		super();
		super.setTrigger(false);
	}

	@Override
	public void update(float delta) {
		super.update(delta);

		float friction = isGround ? 1 : 0;
		Debug.info("玩家isGround: %s, 碰撞列表数: %s", isGround, getStayCollisionColliders().size());
	}

	@Override
	public void setTrigger(boolean trigger){}

	public void setBodyColl(ColliderComponent bodyColl){
		this.bodyColl = bodyColl;
	}


	@Override
	public void onCollisionEnter(ColliderComponent other, FullCollisionResult result) {
		super.onCollisionEnter(other, result);

		if("Ground".equals(other.getTag())){
			isGround = true;
		}
	}

	@Override
	public void onCollisionExit(ColliderComponent other, FullCollisionResult result) {
		super.onCollisionExit(other, result);

		boolean hasGroundColl = false;
		for(ColliderComponent coll : getStayCollisionColliders()){
			if("Ground".equals(coll.getTag())){
				hasGroundColl = true;
				break;
			}
		}
		if(!hasGroundColl){
			isGround = false;
		}
	}

	public boolean isGround() {
		return isGround;
	}
}
